﻿-- Function: tepuy.statusbydoc(character varying, character varying, integer)

-- DROP FUNCTION tepuy.statusbydoc(character varying, character varying, integer);

CREATE OR REPLACE FUNCTION tepuy.statusbydoc(character varying, character varying, integer)
  RETURNS boolean AS
$BODY$
-- Copyright © 2010 Riztan Gutierrez <riztan at gmail dot com>
-- Esto es parte de: proyecto tepuy.
-- Este programa es Software Libre conforme a la GPL Version 3 o posterior.
-- http://www.gnu.org/licenses/
DECLARE
    schematable varchar;
    retval integer;
BEGIN

   schematable := $1 || '.' || 'base_classifier_data ';

  execute 'select clsdata_id from ' || schematable  
          || ' where clsdata_class_id=' || quote_literal($3) 
          || ' and clsdata_value=' || quote_literal($2) 
          || ' limit 1' 
          INTO retval;

  if retval is null then
     return false;
  end if;

  return true;
   
END;
$BODY$
  LANGUAGE 'plpgsql' VOLATILE
  COST 100;
ALTER FUNCTION tepuy.statusbydoc(character varying, character varying, integer) OWNER TO postgres;
COMMENT ON FUNCTION tepuy.statusbydoc(character varying, character varying, integer) IS 'retorna verdadero si el valor para estatus del documento es correcto';
